package com.atguigu.springcloud.config;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;

import reactor.core.publisher.Mono;

/**
 * 全局过滤器链，可配置多个Order
 * @author heh
 * @date 2020-08-29
 */
@Component
public class MyGatewayFilter implements GlobalFilter,Ordered{

	@Override
	public int getOrder() {
 		return 0;
	}

	@Override
	public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
 		
		String first = exchange.getRequest().getQueryParams().getFirst("token");
		/*
		 * if(first == null) { System.out.println("未授权，非法用户");
		 * exchange.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED);
		 * exchange.getResponse().setComplete(); }
		 */
		return chain.filter(exchange);
	}

}
